import tkinter as tk
import subprocess

from singlepart.category import test_category
from singlepart.test_home import test_home
from singlepart.test_up import test_up
from singlepart.test_link import test_link
from singlepart.test_search import test_search
from singlepart.test_login import test_login
from singlepart.test_logout import test_logout


# Tkinter GUI
root = tk.Tk()
root.title("Automated Tests")

frame = tk.Frame(root)
frame.pack(pady=10)

# 单个模块测试标签
tk.Label(frame, text="单个模块测试", font=("Helvetica", 16)).grid(row=0, column=0, columnspan=2, pady=5)

# 前八个单个模块测试按钮

single_module_buttons = [
    ("Get Cookies", lambda: subprocess.run(["python", "singlepart/getcookies.py"])),
    ("Test Login", lambda: test_login()),
    ("Test Logout", lambda: test_logout()),
    ("Test Search", lambda: test_search()),
    ("Test Navigation", lambda: subprocess.run(["python", "singlepart/test_navigation.py"])),
    ("Test link", lambda: test_link()),
    ("Test Home", lambda: test_home()),
    ("Test up", lambda: test_up()),
    ("Test category", lambda: test_category())
]

for i, (text, command) in enumerate(single_module_buttons):
    row = i // 2 + 1  # Adjusting row for label
    col = i % 2
    tk.Button(frame, text=text, command=command).grid(row=row, column=col, padx=10, pady=5)

# 集成模块测试标签
tk.Label(frame, text="集成模块测试", font=("Helvetica", 16)).grid(row=6, column=0, columnspan=2, pady=5)

# 后八个集成模块测试按钮
integration_module_buttons = [
    ("Test1 加入购物车", lambda: subprocess.run(["python", "integratedpart/test_addtocart.py"])),
    ("Test2 意见反馈", lambda: subprocess.run(["python", "integratedpart/test_suggestion.py"])),
    ("Test3 修改联系方式", lambda: subprocess.run(["python", "integratedpart/test_address.py"])),
    ("Test4 查找消息", lambda: subprocess.run(["python","integratedpart/test_message.py"]))
]

for i, (text, command) in enumerate(integration_module_buttons):
    row = i // 2 + 7  # Adjusting row for label and single module buttons
    col = i % 2
    tk.Button(frame, text=text, command=command).grid(row=row, column=col, padx=10, pady=5)

# 并发测试标签
tk.Label(frame, text="并发测试", font=("Helvetica", 16)).grid(row=10, column=0, columnspan=2, pady=5)
tk.Button(frame,text="并发测试",command=lambda:subprocess.run(["python","bingfa.py"]),font=("Helvetica",16)).grid(row=11,column=0,columnspan=2,pady=5)

# 数据组合测试标签
tk.Label(frame, text="数据组合测试", font=("Helvetica", 16)).grid(row=12, column=0, columnspan=2, pady=5)
tk.Button(frame,text="开始测试",command=lambda:subprocess.run(["python","grouptest.py"]),font=("Helvetica",16)).grid(row=13,column=0,columnspan=2,pady=5)

root.mainloop()